package com.xiaoxu.intranetweb.util;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.TemplateConfig;
import com.baomidou.mybatisplus.generator.config.TemplateType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

public class MybatisPlusGenerator {
    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://192.168.1.106:7406/szappdb?useUnicode=true&characterEncoding=utf-8", "szadmin", "szadmin")
                .globalConfig(builder -> {
                    builder.author("lvNuo") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
//                            .fileOverride( ) // 覆盖已生成文件
                            .outputDir("E:\\Dev\\IdeaProjects\\plantProjects\\hrfy\\intranet-web-group-hrfy//src//main//java//"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.xiaoxu.intranetweb.mybatisplusSzappdb") // 设置父包名
                            .moduleName("") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "E:\\Dev\\IdeaProjects\\plantProjects\\hrfy\\intranet-web-group-hrfy//src//main//resources//mapperSzappdb")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("t_sampling_record") // 设置需要生成的表名
                            .addTablePrefix()
                    ; // 设置过滤表前缀
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
        new TemplateConfig.Builder()
                .disable(TemplateType.ENTITY)
                .entity("/entity.java")
                .service("/service.java")
                .serviceImpl("/serviceImpl.java")
                .mapper("/mapper.java")
                .mapperXml("/mapper.xml")
                .controller("/controller.java")
                .build();
        new StrategyConfig.Builder()
                .controllerBuilder()
                .enableHyphenStyle()
                .build();
        new StrategyConfig.Builder()
                .entityBuilder()
                .enableLombok()
                .build();
    }
}
